#include "EngineObject.h"
#include "windows.h"

list<EngineObject*> EngineObject::liveObjects;
list<EngineObject*> EngineObject::deadObjects;

EngineObject::EngineObject(void)
{
	liveObjects.push_back(this);
	this->refCount = 0;
}

EngineObject::~EngineObject(void)
{
}

void EngineObject::CollectGarbage()
{
	for (list<EngineObject*>::iterator it=deadObjects.begin(); it != deadObjects.end(); it++)
	{
		delete (*it);
	}
	deadObjects.clear();
}

void EngineObject::CollectRemainingObjects(bool emitWarnings)
{
	CollectGarbage();
	for (list<EngineObject*>::iterator it=liveObjects.begin(); it != liveObjects.end(); it++)
	{
		EngineObject* o = (*it);
		if (emitWarnings)
		{
			MessageBox(NULL, L"Engine object live after collection", L"Engine object live after collection", MB_OK);
		}
		delete o;
	}
	liveObjects.clear();
}